<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd', changeMonth: true});
	$("input[name='number']").focus();
	<?if (isset($sales_order) && ! empty($sales_order)):?>
	$("#save").focus();
	<?endif;?>
})
</script>
<fieldset>
	<legend>查询条件</legend>
	<form method="get">
	<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
		<table class="form_table">
			<tr>
				<th>订单号/追踪号</th>
				<td><input type="text" name="number" value="<?=empty($_GET['number']) ? '' : $_GET['number'] ?>" focus="true" /></td>
			</tr>
			<tr>
				<th><input type="hidden" name="is_search" value="1" /></th>
				<td><input type="submit" class="button" value="查找" /></td>
			</tr>
		</table>
	</form>
</fieldset>
<?if (isset($report) && ! empty($report)):?>
<table class="list_table" width="100%">
<tr>
	<th>订单号</th>
	<th>追踪号</th>
	<th>网站</th>
	<th>销售</th>
	<th>销售时间</th>
	<th>状态</th>
	<th>操作</th>
</tr>
<?foreach ($report as $r):?>
<tr>
	<td><?=$r['number']?></td>
	<td><?=$r['tracking_number']?></td>
	<td><?=$r['shop_name']?></td>
	<td><?=$r['sales_user_name']?></td>
	<td><?=$r['sales_time']?></td>
	<td>
	<?=Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $r['handle_status'], 'name')?>
	<span class="<?=Helper_BSS_Normal::getIniOne('sales_order_handle_status', 'value', $r['handle_status'], 'icon_class')?>"></span>
	</td>
	<td>
		<?if ($r['handle_status'] == Q::ini('custom_flag/sales_order_handle_status/shipped/value')):?>
		<a href="<?=url('Sales::Order/ReturnCreate', array('id'=>$r['id']))?>" onClick="if(!confirm('确定退货？')) return false;" >退货</a>
		<?else:?>
		退货
		<?endif;?>
	</td>
</tr>
<?endforeach;?>
</table>
<?endif;?>
<?if ( ! empty($sales_order)):?>
<form method="post" action="<?=url('Sales::Order/ReturnCreateSave')?>">
<h2>新增销售退货单</h2>
<table class="form_table">
	<tr>
		<th>销售订单号</th>
		<td><?=$sales_order['number']?><input type="hidden" name="number" value="<?=$sales_order['number']?>"/></td>
		<th>退货日期</th>
		<td><input type="text" name="return_time" class="datepicker" value="<?=CURRENT_DATETIME?>" /></td>
	</tr>
	<tr>
		<th>退货原因</th>
		<td colspan="3"><textarea rows="3" cols="50" name="reason"></textarea></td>
	</tr>
</table>
<h2>销售单产品信息</h2>
<table class="list_table">
	<tr>
		<th width="50">选择</th>
		<th width="50">ID</th>
		<th width="250">产品型号</th>
		<th width="80">销售数量</th>
		<th width="80">退货数量</th>
	</tr>
	<?foreach ($sales_order_item as $i):?>
	<tr>
		<td><input type="checkbox" name="check<?=$i['id']?>" value="<?=$i['id']?>" checked="checked" /></td>
		<td><?=$i['id']?></td>
		<td>(<?=$i['number']?>) <?=$i['name']?><input type="hidden" name="product_basic_id<?=$i['id']?>" value="<?=$i['product_basic_id']?>"/></td>
		<td><?=$i['quantity']?></td>
		<td><input type="text" name="quantity<?=$i['id']?>" size="2" value="<?=$i['quantity']?>" /></td>
	</tr>
	<?endforeach;?>
</table>
<input type="submit" id="save" class="button" value="保存" />
<input type="hidden" name="<?=Q::ini('unique_token_name');?>" value="<?=Helper_BSS_Normal::genToken();?>"/>
</form>
<?endif;?>
<?php $this->_endblock();?>